import { McRequest } from './McRequest'
import { defaultConfig } from './config'
import { IRequestHook, IResponseHook, IOptions, Ictr } from './types'

/**创建请求实例 */
export function createRequest(
  options?: IOptions,
  requestHooks?: IRequestHook[],
  responseHooks?: IResponseHook[],
  ctr?: Ictr
) {
  const o = Object.assign({}, defaultConfig.options, options)
  const reqH = requestHooks || defaultConfig.requestHooks
  const resH = responseHooks || defaultConfig.responseHooks
  const c = Object.assign({}, defaultConfig.ctr, ctr)
  const request = new McRequest(o, reqH, resH, c)
  return request
}
